home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / ieee-utils / env.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-22  |  3.0 KB  |  115 lines

  1. /* ieee-utils/env.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <config.h>
  21. #include <stdlib.h>
  22. #include <gsl/gsl_ieee_utils.h>
  23. #include <gsl/gsl_errno.h>
  24.  
  25. void
  26. gsl_ieee_env_setup (void)
  27. {
  28.   const char * p = getenv("GSL_IEEE_MODE") ;
  29.  
  30.   int precision = 0, rounding = 0, exception_mask = 0 ;
  31.  
  32.   int comma = 0 ;
  33.  
  34.   if (p == 0)  /* GSL_IEEE_MODE environment variable is not set */
  35.     return ;
  36.  
  37.   if (*p == '\0') /* GSL_IEEE_MODE environment variable is empty */
  38.     return ;
  39.  
  40.   gsl_ieee_read_mode_string (p, &precision, &rounding, &exception_mask) ;
  41.  
  42.   gsl_ieee_set_mode (precision, rounding, exception_mask) ;
  43.   
  44.   fprintf(stderr, "GSL_IEEE_MODE=\"") ;
  45.  
  46.   /* Print string with a preceeding comma if the list has already begun */
  47.  
  48. #define PRINTC(x) do {if(comma) fprintf(stderr,","); fprintf(stderr,x); comma++ ;} while(0)
  49.   
  50.   switch (precision) 
  51.     {
  52.     case GSL_IEEE_SINGLE_PRECISION:
  53.       PRINTC("single-precision") ;
  54.       break ;
  55.     case GSL_IEEE_DOUBLE_PRECISION:
  56.       PRINTC("double-precision") ;
  57.       break ;
  58.     case GSL_IEEE_EXTENDED_PRECISION:
  59.       PRINTC("extended-precision") ;
  60.       break ;
  61.     }
  62.  
  63.   switch (rounding) 
  64.     {
  65.     case GSL_IEEE_ROUND_TO_NEAREST:
  66.       PRINTC("round-to-nearest") ;
  67.       break ;
  68.     case GSL_IEEE_ROUND_DOWN:
  69.       PRINTC("round-down") ;
  70.       break ;
  71.     case GSL_IEEE_ROUND_UP:
  72.       PRINTC("round-up") ;
  73.       break ;
  74.     case GSL_IEEE_ROUND_TO_ZERO:
  75.       PRINTC("round-to-zero") ;
  76.       break ;
  77.     }
  78.  
  79.   if ((exception_mask & GSL_IEEE_MASK_ALL) == GSL_IEEE_MASK_ALL)
  80.     {
  81.       PRINTC("mask-all") ;
  82.     }
  83.   else if ((exception_mask & GSL_IEEE_MASK_ALL) == 0)
  84.     {
  85.       PRINTC("trap-common") ;
  86.     }
  87.   else 
  88.     {
  89.       if (exception_mask & GSL_IEEE_MASK_INVALID)
  90.     PRINTC("mask-invalid") ;
  91.       
  92.       if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  93.     PRINTC("mask-denormalized") ;
  94.       
  95.       if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  96.     PRINTC("mask-division-by-zero") ;
  97.       
  98.       if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  99.     PRINTC("mask-overflow") ;
  100.       
  101.       if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  102.     PRINTC("mask-underflow") ;
  103.     }
  104.  
  105.   if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  106.     PRINTC("trap-inexact") ;
  107.   
  108.   fprintf(stderr,"\"\n") ;
  109. }
  110.  
  111.  
  112.  
  113.  
  114.  
  115.